package 插入数据;

import java.sql.*;

public class demo01 {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost/db_jdbc_demo?jdbc:mysql://IP地址:3306/数据库名称?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
        String user = "root";
        String pass = "200233";
        Connection conn= null;
        PreparedStatement pstmt =null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url,user,pass);
            String sql = "INSERT INTO t_account (id,name,money) VALUES (?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1,5);
            pstmt.setString(2,"郑文杰");
            pstmt.setInt(3,4000000);
            int i = pstmt.executeUpdate();
            if (i==1){
                System.out.println("插入成功");
            }else {
                System.out.println("插入失败");
            }
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                pstmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
